package com.lanou.controller.T8TController;

import com.lanou.service.T8TService.ShoppingCartService;
import com.lanou.utils.AjaxResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by dllo on 18/3/19.
 */
@Controller
public class ShoppingCart {

    @Resource
    ShoppingCartService shoppingCartService;

    @ResponseBody
    @RequestMapping(value = "/addCart")
    public AjaxResult addCart(@RequestParam(value = "commodityId") Integer commodityId,
                        @RequestParam(value = "colorId") Integer colorId,
                        @RequestParam(value = "size") Integer sizeId,
                        @RequestParam(value = "userId") Integer userId,
                        @RequestParam(value = "count") Integer count) {
        shoppingCartService.addCart(commodityId, colorId, sizeId, userId, count);
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setMsg("成功");
        ajaxResult.setCode("1");
        return ajaxResult;
    }

    @ResponseBody
    @RequestMapping(value = "/allCart")
    public AjaxResult selectAllCart(@RequestParam("userId") Integer userId) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode("1");
        ajaxResult.setMsg("成功");
        ajaxResult.setData(shoppingCartService.selectUserCart(userId));
        return ajaxResult;
    }


}
